package com.liang.excel.core.domain;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 常见的指数
 *
 * @author liangyehao
 * @version 1.0
 * @date 2021/4/25 0:53
 * @content
 */
@Data
public class CommonIndex {

    private Integer sessionAmount = 0;

    private Integer inputAmount = 0;

    private BigDecimal inputRate = new BigDecimal(0);

    private Integer takeLookAtAmount = 0;

    private BigDecimal takeLookAtRate = new BigDecimal(0);


    public static CommonIndex build(List<BusinessData> businessData){
        CommonIndex commonIndex = new CommonIndex();
        if (businessData==null || businessData.size()==0) {
            return commonIndex;
        }

        // IM唯一会话量
        int sessionAmount = businessData.size();

        // IM录入量
        List<BusinessData> inputData = businessData.stream().filter(data ->
                "商机后录入".equals(data.getRecordGuestIs()) &&
                        data.getTurnGuestCycle() != null &&
                        Integer.parseInt(data.getTurnGuestCycle()) < 7)
                .collect(Collectors.toList());
        int inputAmount = inputData.size();

        // IM录入率
        BigDecimal inputRate = BigDecimal.valueOf((float)inputAmount/sessionAmount);

        // IM带看量
        List<BusinessData> takeLookAt = inputData.stream().filter(session ->
                session.getTurnWithPeriod() != null && Integer.parseInt(session.getTurnWithPeriod()) < 7)
                .collect(Collectors.toList());
        int takeLookAtAmount = takeLookAt.size();

        // IM带看率
        BigDecimal takeLookAtRate = BigDecimal.valueOf((float)takeLookAtAmount/sessionAmount);

        commonIndex.setSessionAmount(sessionAmount);
        commonIndex.setInputAmount(inputAmount);
        commonIndex.setInputRate(inputRate);
        commonIndex.setTakeLookAtAmount(takeLookAtAmount);
        commonIndex.setTakeLookAtRate(takeLookAtRate);

        return commonIndex;
    }

}
